package cn.yl.caner.service;

import java.sql.SQLException;

import cn.yl.caner.dao.AddDao;
import cn.yl.caner.domain.AddData;
import cn.yl.caner.utils.MyDataSourceUtils;

public class AddService {
	
	public int addAccount(AddData adddata) {
		//service层，对注册信息提交事务，转换至DAO层
		int i = 0;
		AddDao adddao = new AddDao();
		try {
			//设置事务，获取连接
			MyDataSourceUtils.start();
			i = adddao.addAccount(adddata);
		} catch (Exception e) {
			try {
				//回滚
				MyDataSourceUtils.rollback();
			} catch (SQLException e1) {
				System.out.println("事物回滚失败！！");
			}
			System.out.println("事物出现错误！");
		}finally {
			try {
				//提交
				MyDataSourceUtils.commit();
			} catch (SQLException e) {
				System.out.println("事物提交失败！！");
			}
		}
		
			return i;
	}		
}
